package com.tedu.show.menus;

import com.tedu.manager.GameLoad;

import javax.swing.*;
import java.awt.*;

public class BaseScreen extends JPanel {
    private final ImageIcon background;

    /**
     * 构造一个带有背景图的屏幕
     * @param imageKey 背景图的键
     */
    public BaseScreen(String imageKey) {
        this.setLayout(null); // 所有菜单界面都使用绝对布局
        ImageIcon icon = GameLoad.imgMap.get(imageKey);
        if (icon == null) {
            System.err.println("警告：在配置文件中找不到背景图片键: " + imageKey);
        }
        this.background = icon;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 绘制背景图片，使其填满整个面板
        if (background != null) {
            g.drawImage(background.getImage(), 0, 0, getWidth(), getHeight(), this);
        }
    }
}
